//
//  ViewController.m
//  YXImageBrowserDemo
//
//  Created by guo peng huang on 2021/5/16.
//

#import "YXMainViewController.h"
#import "YXBaseListViewController.h"
#import "YXImageVideoViewController.h"
#import "YXLookOriginalImageViewController.h"
#import "YXCustomCellViewController.h"
#import "YXTestDelegateViewController.h"
#import "YXAddViewController.h"

@interface YXMainViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray<Class> *controllers;

@end

@implementation YXMainViewController

#pragma mark - *_* life cycle *_*
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"YXImageBrowserDemo";
    self.controllers = @[
                        YXImageVideoViewController.self,
                        YXLookOriginalImageViewController.self,
                        YXCustomCellViewController.self,
                        YXTestDelegateViewController.self,
                        YXAddViewController.self
                        ];
    [self initSubView];
}

- (void)initSubView {
    [self.view addSubview:self.tableView];
    self.tableView.frame = self.view.bounds;
}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
}

#pragma mark - <UITableViewDataSource, UITableViewDelegate>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.controllers.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString * const kCellIdentifier = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.font = [UIFont boldSystemFontOfSize:17];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.textLabel.text = [self.controllers[indexPath.row] yx_title];
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    YXBaseListViewController *vc = [self.controllers[indexPath.row] new];
    vc.title = [vc.class yx_title];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - *_* lazyLoad *_*
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
//        if (@available(iOS 11.0, *)) {
//            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//        }
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 34, 0);
        _tableView.tableFooterView = [UIView new];
    }
    return _tableView;
}

@end
